---@class Battle.EffectConditionData
local EffectConditionData = Battle.CreateClass("EffectConditionData",Battle.BaseComponent)
Battle.EffectConditionData = EffectConditionData

function EffectConditionData:ctor()
    ---@type Battle.Buffer
    self.buff = nil
    self.conditionTargetType = 0
    self.conditionAttrType = 0
    self.conditionAttrValue = 0
    --效果影响
    self.impactTargetType = 0
    self.impactTargetValue = 0
    self.impactType = 0
    self.impactValue = 0
end
---效果触发条件
function EffectConditionData:SetConditionTarget(effectConditionTargetType,value)
    self.effectConditionTargetType = effectConditionTargetType

end
function EffectConditionData:SetConditionType(effectConditionAttrType,effectConditionAttrValue)
    self.effectConditionAttrType = effectConditionAttrType
    self.effectConditionAttrValue = effectConditionAttrValue
end
---效果影响值
function EffectConditionData:SetImpactTarget(effectConditionImpactTargetType,value)
    self.impactTargetType = effectConditionImpactTargetType
    self.impactTargetValue = value
end
function EffectConditionData:SetImpactType(effectConditionImpactType,value)
    self.impactType = effectConditionImpactType
    self.impactValue = value
end

function EffectConditionData:Execute(buff)
    self.buff = buff
    local value = self:CheckCondition()
    self:CheckImpact(value)
end

function EffectConditionData:CheckCondition()
    ---@type Battle.Entity
    local actor = nil
    if self.effectConditionTargetType == Battle.EffectConditionTargetType.Caster then
        actor = self.buff.sourceSender
    elseif self.effectConditionTargetType == Battle.EffectConditionTargetType.Target then
        actor = Battle.ActorManager.GetActor(self.buff.targetId)
    end
    local value = 0
    if self.effectConditionAttrType == Battle.EffectConditionAttrType.HPLostPer then
        local hp = (actor:GetHpMax() - actor:GetHp())/actor:GetHpMax()
        value = math.floor(hp * 10000 / self.effectConditionAttrValue)
    end
    return value
end
function EffectConditionData:CheckImpact(conditionValue)
    if self.impactTargetType == Battle.EffectConditionImpactTargetType.Self then
        self:CheckImpactBuff(self.buff,conditionValue)
    end
end
---@param buff Battle.Buffer
function EffectConditionData:CheckImpactBuff(buff,conditionValue)
    if self.impactType == Battle.EffectConditionImpactType.DuringTime then
        buff:SetDuring(buff.during + self.impactValue/1000 * conditionValue)
    end
end